package com.wlsk.license.common.utils;

import cn.hutool.core.date.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.Date;
import java.util.UUID;

/**
 * <p>@Description : 文件工具</p>
 * <p>@Author : Zhangbin.Liu </p>
 * <p>@Date : 2019/9/12 16:46 </p>
 */
public final class PathFileUtils {

    private static Logger logger = LoggerFactory.getLogger(PathFileUtils.class);

    private static final String CHARTERED_BUS_TEMP = "chartered_bus_temp";

    private static final String SYSTEM_TMPDIR = System.getProperty("java.io.tmpdir");

    static {
        File file = new File(SYSTEM_TMPDIR.concat(File.separator).concat(CHARTERED_BUS_TEMP));
        if (!file.exists()) {
            file.mkdirs();
        }
        logger.info("临时文件存储目录:{}", file.getAbsolutePath());
    }

    /**
     * 获取excel文件存放临时目录
     *
     * @return
     */
    public static String getPath() {
        String path = SYSTEM_TMPDIR.concat(File.separator).concat(CHARTERED_BUS_TEMP).concat(File.separator);
        String uuid = UUID.randomUUID().toString();
        path = path.concat(uuid).concat(File.separator);
        File file = new File(path);
        if (!file.exists()) {
            file.mkdirs();
        }
        return path;
    }

    /**
     * 获取生成文件名称
     *
     * @param name .xls
     * @return
     */
    public static String getFileName(String name, String type) {
        Date now = DateUtil.date();
        String formatDateTime = DateUtil.format(now, "yyyyMMddHHmmss");
        return name.concat("_").concat(formatDateTime).concat(type);
    }

}
